본문 바로가기
언어/R

basic

by newlibra 2025. 4. 30.

https://www.w3resource.com/r-programming-exercises/

 

R programming Exercises, Practice, Solution - w3resource

R programming Exercises, Practice, Solution: The best way we learn anything is by practice and exercise questions. Here you have the opportunity to practice the R programming language concepts by solving the exercises starting from basic to more complex ex

www.w3resource.com

 

https://www.w3schools.com/r/exercise.asp

 

W3Schools R Exercise

I completed all the R exercises on w3schools.com

www.w3schools.com

 

 

터미널에서..

>Rscript ~~.R

또는

R 상태에서

R> source("~~.R")

 

basic1.R

name <- readline(prompt="Inputer your name : ")
age <- readline(prompt="Inputer your age : ")
print(paste("Your name is : ", name, " and your age is : ", age))
print(R.version.string)

 

 

basic2.R

name = "korea"
n1 = 10
n2 = 0.5
nums = c(10,20,30,40,50,60)
print(ls())
print("Details of the objects in memory: ")
print(ls.str())

 

basic3.R

print("Sequence of numbers from 20 to 50 :")
print(seq(20,50))
print("Mean of numbers from 20 to 60 :")
print(mean(20:60))
print("Sum of numbers from 51 to 91 :")
print(sum(51:91))

 

basic4.R

v = sample(-50:50, 10, replace=FALSE)
print("Content of the vector :")
print("10 random integer values between -50 and +50 :")
print(v)

 

basic5.R

Fibonacci <- numeric(10)
Fibonacci[1] <- Fibonacci[2] <- 1

for(i in 3:10) Fibonacci[i] <- Fibonacci[i-2] + Fibonacci[i-1]

print("First 10 Fibonacci numbers :")
print(Fibonacci)

 

basic6.R

prime_numbers <- function(n)
{
  if(n >=2) 
  {
    x = seq(2,n)
    prime_nums = c()
    
    for(i in seq(2,n))
    {
      if(any(x == i))
      {
        prime_nums = c(prime_nums, i)
        x = c(x[(x %% i) != 0], i)
      }
    }
    
    return (prime_nums)
  }
  else {
    stop("Input number should be at least 2. ")
  }
}

#prime_numbers(12)

'언어 > R' 카테고리의 다른 글

R statistics  (0) 2025.04.19
R foreach  (0) 2025.03.26
R BlackSholes  (0) 2025.02.19
엑셀파일 읽고 csv 파일 저장  (0) 2025.02.02
ggplot2  (0) 2025.01.28